/**
 * 
 */
package org.hackystat.project;

import static org.junit.Assert.*;
import java.util.List;
import org.hackystat.projecttrajectory.ProjectTrajectoryProperties;
import org.hackystat.projecttrajectory.test.ProjectTrajectoryTestHelper;
import org.hackystat.sensorbase.resource.projects.jaxb.Project;
import org.hackystat.utilities.stacktrace.StackTrace;
import org.junit.Test;

/**
 * Test cases for PersonalProjectSummaryFactory.
 * @author Cam Moore
 */
public class TestPersonalProjectSummaryFactory extends ProjectTrajectoryTestHelper {

  /**
   * Test method for {@link org.hackystat.project.PersonalProjectSummaryFactory#getInstance()}.
   */
  @Test
  public void testGetInstance() {
    PersonalProjectSummaryFactory factory;
    try {
    	// Just in case.
    	ProjectTrajectoryProperties properties = ProjectTrajectoryProperties.getInstance();
      properties.setTestProperties();

      factory = PersonalProjectSummaryFactory.getInstance();
      assertNotNull("got null factory", factory);
      List<Project> projects = factory.getProjects();
      assertNotNull("Got null projects", projects);
      assertFalse("Got empty projects", projects.isEmpty());
      Project p = projects.get(0); // just grab the first one.
      System.out.println("Summary for " + p.getName());
      ProjectSummary summary = factory.getLatestSummary(p);
      assertNotNull("Got null Summary for " + p.getName(), summary);
      // test some of the attributes of ProjectSummary
      assertEquals("Wrong project name", p.getName(), summary.getProjectName());
      List<ProjectSummary> summaries = factory.getSummaries(p);
      assertNotNull("Got null list", summaries);
      if (summary.getActiveDays() > 0) {
        // the project has no active days so there are no daily summaries
        assertFalse("No summaries", summaries.isEmpty());
      } else {
        assertTrue("summary list should be empty", summaries.isEmpty());
        assertEquals("Effort should be 0", 0l, summary.getTotalEffort());
        assertEquals("Size should be 0", 0.0, summary.getTotalLines(), 0.00001);
        assertEquals("Duration days should be 0", 0l, summary.getDurationDays());
      }
    } catch (ProjectException e) {
      fail("Got an Exception: " + StackTrace.toString(e));
    }
  }
  
}
